<h2>Thay Đổi Thông Tin Đơn Hàng</h2>
<form name="edit_invoice" action="?act=createOrModifyInvoice&invoice_id=<?php echo (isset($invoice_id)? $invoice_id:"")  ?>" method="POST" onsubmit="return validate_values()" enctype="multipart/form-data">
	<div class='row_field'>
    	<div class='label'>
			<label for="invoice_type">Cá Nhân/Cty (*):</label>
        </div>
        <div class='field'>
			<select class='inputbox' id='invoice_type' name='invoice_type' onchange="changeType()">
				<option value="INDIVIDUAL" <?php echo ($invoice->gettype() == 'INDIVIDUAL') ? 'selected="selected"':'' ?>>Cá Nhân</option>
				<option value="COMPANY" <?php echo ($invoice->gettype() == 'COMPANY') ? 'selected="selected"':'' ?>>Công Ty</option>
			</select>
        </div>
	</div>
	
	
	<div class='row_field'>
    	<div class='label'>
			<label for="user_id">Tên Khách Hàng (*):</label>
        </div>
		<div class='field'>
			<?php
				$user = new User();
				$user->select($invoice->getuser_id());
			?>
			<input disabled="disabled" class='inputbox' id="user_id" name="user_id" value="<?php echo $user->getname()?>">
        </div>
    </div>


	<div id='company_info' style="<?php echo ($invoice->gettype() != 'COMPANY' ) ? 'display:none' : ''?>">
		<div class='row_field' >
    		<div class='label'>
				<label for="company_name">Tên Công Ty (*):</label>
        	</div>
			<div class='field'>
				<input class='inputbox' id="company_name" name="company_name" value="<?php echo $invoice->getcompany_name() ?>">
        	</div>
    	</div>

		<div class='row_field' >
    		<div class='label'>
				<label for="company_tax_code">Mã Số Thuế (*):</label>
        	</div>
			<div class='field'>
				<input class='inputbox' id="company_tax_code" name="company_tax_code" value="<?php echo $invoice->gettax_code() ?>">
        	</div>
    	</div>
	</div>
	
	
	<div class='row_field'>
    	<div class='label'>
			<label for="payment_method">Phương Thức Thanh Toán (*):</label>
        </div>
        <div class='field'>
			<select class='inputbox' id='payment_method' name='payment_method'>
				<option value="CREDIT_CARD" <?php echo ($invoice->getpayment_method() == 'CREDIT_CARD') ? 'selected="selected"':'' ?>>Thẻ Tín Dụng</option>
				<option value="TRANSFER" <?php echo ($invoice->getpayment_method() == 'TRANSFER') ? 'selected="selected"':'' ?>>Chuyển Khoản</option>
				<option value="CASH" <?php echo ($invoice->getpayment_method() == 'CASH') ? 'selected="selected"':'' ?>>Tiền Mặt</option>
			</select>
        </div>
	</div>
	
	
	<div class='row_field'>
    	<div class='label'>
			<label for="status">Trạng Thái Đơn Hàng (*):</label>
        </div>
        <div class='field'>
			<select class='inputbox' id='status' name='status'>
				<option value="CREATE" <?php echo ($invoice->getstatus() == 'CREATE') ? 'selected="selected"':'' ?>>Khởi tạo</option>
				<option value="PENDING" <?php echo ($invoice->getstatus() == 'PENDING') ? 'selected="selected"':'' ?>>Đang xử lý</option>
				<option value="APPROVE" <?php echo ($invoice->getstatus() == 'APPROVE') ? 'selected="selected"':'' ?>>Xác nhận</option>
				<option value="COMPLETE" <?php echo ($invoice->getstatus() == 'COMPLETE') ? 'selected="selected"':'' ?>>Hoàn tất</option>
				<option value="CANCEL" <?php echo ($invoice->getstatus() == 'CANCEL') ? 'selected="selected"':'' ?>>Huỷ</option>
			</select>
        </div>
	</div>
   
	<div class='row_field'><p>(*) Thông tin bắt buộc</p></div>
	<div class='row_field'>
		<input type="submit" value="Save">
		<input type="reset" value="Reset" onclick="reloadCompanyBlock()">
	</div>
	
</form>
<script type="text/javascript">
	function validate_values() {
		category = $('#category').val();
		description = $('#description').val();
		
		message = "Các mục sau đây là bắt buộc hoặc sai giá trị: \n";
		ok = true;
		if (category == "") {
			message += "Danh mục \n";
			ok = false;
		}
		if (description == "") {
			message += "Mô tả \n";
			ok = false;
		}
		if (!ok) alert(message);
		return ok;
	}
	
	
	function changeType()
	{
		value = $('#invoice_type').val();
		if (value == 'COMPANY') {
			$('#company_info').show();
		} else {
			$('#company_info').hide();
		}
	}
	
	
	function reloadCompanyBlock()
	{
		<?php if ($invoice->gettype() != 'COMPANY'): ?>
			$('#company_info').hide();
		<?php else: ?>
			$('#company_info').show();
		<?php endif ?>
	}
</script>